package chapter03;

public class Test01_extends {
    public static void main(String[] args) {
        Dog d = new Dog("小黄",20,"黄色");
        System.out.println(d.getName());
        System.out.println(d.getAge());
        System.out.println(d.getColor());
        d.shout();
    }
}
class Animal{
    private String name;
    private int age;
    final int weight = 20;//常量 不能更改
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void shout(){
        System.out.println("动物发出声音");
    }
}
class Dog extends Animal{
    private String color;
    public Dog(String name, int age, String color) {
        super(name, age);//调用父类的构造方法
        this.color = color;
    }

    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public void shout(){
        super.shout();//调用了父类的方法
        System.out.println("汪汪");
    }
}
